<?php

namespace App\Http\Controllers;

use App\Repositories\ParticipateRepository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;

class ParticipateController extends Controller
{

    protected $model;

    public function __construct(ParticipateRepository $participate)
    {
        $this->model=$participate;
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        if(!empty($request->input('name'))){
            $enterprise=$this->model->page(15,'desc','created_at');
        }else{
            $enterprise=$this->model->getRecordByLikeSearch('topic','like','%'.$request->input('name').'%');
        }


        return view('admin.participate.index',['enterprise'=>$enterprise]);
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     * participate/create Get
     */
    public function create()
    {
        return view('index.organize');
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     * participate  post
     */
    public function store(Request $request)
    {
        if($this->model->store(Input::all())){

            return ['status_code'=>200];
        }else{
            return ['status_code'=>500,'msg'=>'网络错误'];
        }

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     *  participate/{participate}   GET
     */
    public function show($id)
    {
        $data=$this->model->getById($id);

        return view('admin.participate.detail',['data'=>$data]);
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
